#include "QQApplication.h"

QQAppEventFilter::QQAppEventFilter(QObject* parent)
	:QObject(parent)
{
}

bool QQAppEventFilter::eventFilter(QObject* watched, QEvent* event)
{
	switch (event->type())
	{
	case QEvent::MouseButtonPress:
	{
		QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
		emit mousePress(mouse_event->pos(), mouse_event->button());
		break;
	}
	default:
		break;
	}
	return QObject::eventFilter(watched, event);
}

QQApplication::QQApplication(int& argc, char** argv, int ApplicationFlags)
	:QApplication(argc, argv, ApplicationFlags)
{
	//behand this mime database,just for faster
	QQSystemApi::getFileMimeType("");
	eApp->init();
	//qq_settings->init();
	mAppEventFilter = new QQAppEventFilter(this);
	this->installEventFilter(mAppEventFilter);
	mEntryContorller = new QQEntryController();
	//mEntryContorller->showView();
	mClientController = new QQClientController();
	mClientController->showView();
	connect(mEntryContorller, &QQEntryController::entrySuccess, this, &QQApplication::doEntrySuccess);
	connect(mAppEventFilter, &QQAppEventFilter::mousePress, mClientController, &QQClientController::doMousePress);
}

QQApplication::~QQApplication()
{
	if (mEntryContorller)
		delete mEntryContorller;
	if (mClientController)
		delete mClientController;
	//qq_settings->destroy();
}

void QQApplication::doEntrySuccess(const QString& account)
{
	if (mClientController == nullptr)
		mClientController = new QQClientController();
	connect(mAppEventFilter, &QQAppEventFilter::mousePress, mClientController, &QQClientController::doMousePress);
	mEntryContorller->closeView();
	mClientController->showView();
}
